package com.xdcplus.web.controller.wip;


import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.pager.vo.PageVO;
import com.xdcplus.web.common.pojo.dto.wip.WipTaskDTO;
import com.xdcplus.web.common.pojo.dto.wip.WipTaskFilterDTO;
import com.xdcplus.web.common.pojo.vo.wip.WipTaskVO;
import com.xdcplus.web.service.wip.WipTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 岗位任务(WipTask)表服务控制层
 *
 * @author Devin.sang
 * @since 2023-07-03 13:30:08
 */
@Api(tags = "岗位任务(WipTask)")
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("wipTask")
public class WipTaskController extends AbstractController {

    @Autowired
    private WipTaskService wipTaskService;

    @ApiOperation("新增岗位任务")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveWipTask(@RequestBody @Valid WipTaskDTO wipTaskDTO) {

        log.info("saveWipTask {}", wipTaskDTO.toString());

        wipTaskDTO.setCreatedUser(getAccount());
        wipTaskService.saveWipTask(wipTaskDTO);

        return ResponseVO.success();
    }

    @ApiOperation("修改岗位任务")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateWipTask(@RequestBody @Valid WipTaskDTO wipTaskDTO) {

        log.info("updateWipTask {}", wipTaskDTO.toString());

        wipTaskDTO.setUpdatedUser(getAccount());
        wipTaskService.updateWipTask(wipTaskDTO);

        return ResponseVO.success();
    }

    @ApiOperation("查询岗位任务")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<PageVO<WipTaskVO>> findWipTask(WipTaskFilterDTO wipTaskFilterDTO) {

        log.info("findWipTask {}", wipTaskFilterDTO);
        return ResponseVO.success(wipTaskService.queryWipTask(wipTaskFilterDTO));
    }

    @ApiOperation("查询岗位任务(requestIds)")
    @PostMapping(value = "/condition", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<List<WipTaskVO>> findWipTaskByRequestIds(@RequestBody WipTaskFilterDTO wipTaskFilterDTO) {

        log.info("findWipTaskByRequestIds {}", wipTaskFilterDTO);
        return ResponseVO.success(wipTaskService.queryWipTaskByRequestIds(wipTaskFilterDTO));
    }


}
